package com.longcheer.weibo;

import com.longcheer.weibo.vo.User;
import com.weibo.net.WeiboException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class ProfileActivity extends Activity {
    
    private static final String TAG = "ProfileActivity";
    
    private ImageView avatar;
    private TextView nick;
    private TextView location;
    private TextView intro;
    private TextView friendNum;
    private TextView followNum;
    private TextView weiboNum;
    private TextView favouriteNum;
    
    private User user;
    private boolean main;
    private ProvinceManager mProvinceManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.profile);
        findViews();
        
        mProvinceManager = ProvinceManager.getInstance(this);
 
        Bundle data = getIntent().getExtras();
        user = (User)data.getSerializable("user");
        main = data.getBoolean("main", false);
        
        avatar.setImageResource(R.drawable.portrait);
        nick.setText(user.getScreenName());
        location.setText(mProvinceManager.getUserProvinceString(this, user));
        intro.setText(user.getDescription());
        friendNum.setText("" + user.getFriendsCount());
        followNum.setText("" + user.getFollowersCount());
        weiboNum.setText("" + user.getStatusesCount());
        favouriteNum.setText("" + user.getFavouritesCount());
        
        friendNum.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v == friendNum) {
                    startUserList(false);
                }
            }
        });
        
        followNum.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v == followNum) {
                    startUserList(true);
                }
            }
        });        
    }
    
    private void startUserList(boolean follow) {
//        Intent intent = new Intent().setClass(this, UserList.class);
//        intent.putExtra("follow", follow);
//        intent.putExtra("userId", user.getId());
//        startActivity(intent);
    }
    
    private void findViews() {
        avatar = (ImageView)findViewById(R.id.iv_user_profile_avatar);
        nick = (TextView)findViewById(R.id.tv_user_profile_nick);
        location = (TextView)findViewById(R.id.tv_user_profile_loc);
        intro = (TextView)findViewById(R.id.tv_user_profile_intro);
        friendNum = (TextView)findViewById(R.id.tv_user_profile_friends);
        followNum = (TextView)findViewById(R.id.tv_user_profile_follows);
        weiboNum = (TextView)findViewById(R.id.tv_user_profile_weibos);
        favouriteNum = (TextView)findViewById(R.id.tv_user_profile_favourites);
    }
    
    @Override
    public void onBackPressed() {
        if (main) {
            new ExitConfirmDialog(this).show();
        } else {
            super.onBackPressed();
        }
    }
}